﻿using HuaCheng.Controller;
using HuaCheng.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HuaCheng.Views
{    
    public partial class SimuStep : Form
    {
        public bool Result;
        public SimuPage simuPage;
        public SimuStep(SimuPage simuPage)
        {
            InitializeComponent();           
            cboMode.SelectedIndex = 0;
            cboTimeUnit.SelectedIndex = 1;
            cboCurrentUnit.SelectedIndex = 1;
            txtFilePath.Text = simuPage.FilePath;
            lblOldPath.Text = simuPage.FilePath;
            txtBeginRow.Text = simuPage.BeginRow.ToString();
            txtEndRow.Text = simuPage.EndRow.ToString();            
            txtRate.Text = simuPage.Rate.ToString();
            cboMode.Text = simuPage.Mode;
            cboTimeUnit.Text = simuPage.TimeUnit;
            cboCurrentUnit.Text = simuPage.CurrUnit;
            txtTimeCol.Text = simuPage.TimeCol;
            txtCurrentCol.Text = simuPage.CurrCol;
        }

        private void btnBrowser_Click(object sender, EventArgs e)
        {
            odlgExcelFile.Filter = "Excel文件，文本文件|*.xlsx;*.xls;*.txt|Excel文件|*.xlsx;*.xls|文本文件|*.txt";
            odlgExcelFile.RestoreDirectory = true;
            odlgExcelFile.FilterIndex = 1;
            if(odlgExcelFile.ShowDialog() == DialogResult.OK)
            {
                txtFilePath.Text = odlgExcelFile.FileName;
                txtCurrentCol.ReadOnly = false;
                txtTimeCol.ReadOnly = false;
                //DataSet ds = ExcelControl.GetDataByExcel(odlgExcelFile.FileName);
                //MessageBox.Show(ds.Tables[0].Rows[1].ItemArray[1].ToString());
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Result = true;
            simuPage = new SimuPage();
            simuPage.FilePath = txtFilePath.Text;
            simuPage.BeginRow = int.Parse(txtBeginRow.Text);
            simuPage.EndRow = int.Parse(txtEndRow.Text);
            simuPage.Mode = cboMode.Text;
            simuPage.TimeUnit = cboTimeUnit.Text;
            simuPage.CurrUnit = cboCurrentUnit.Text;
            simuPage.Rate = int.Parse(txtRate.Text);
            simuPage.TimeCol = txtTimeCol.Text;
            simuPage.CurrCol = txtCurrentCol.Text;
            this.Close();
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            Result = false;
            this.Close();
        }
    }
}
